module.exports = function ($scope, $resource, $modal, toaster) {


	$scope.getTravelList = function() {
		$scope.searchform.loading = true;
		$resource('/api/as/goc/outboundtravel/getTravelList', {}, {}).save($scope.searchform, function(res){
            if (res.errcode === 0) {
				$scope.list = res.data;
				$scope.searchform.loading = false;
            } else {
                toaster.error({title: '', body: '查询出境游信息失败'});
            }
        });
	}
	
	init();
	function init() {
		$scope.searchform = {};
		$scope.statusInfo = {
			'ss0': '未提交',
			'ss1': '审核中',
			'ss2': '已通过',
			'ss3': '被驳回'
		}
		$scope.getTravelList();
	}

	$scope.addTravel = function(){
		var modalInstance = $modal.open({
			template: require('../views/addTravel.html'),
			controller: 'addTravel',
			size: 'lg',
			resolve: {
				travel: function () {
					return null;
				}
			}
		});
		modalInstance.result.then(function(result) {
			$scope.getTravelList();
		});
	}

	$scope.getInfo = function(info){
		var modalInstance = $modal.open({
			template: require('../views/travelInfo.html'),
			controller: 'travelInfo',
			size: 'lg',
			resolve: {
				travel: function () {
					return info;
				},
				checkFlag: function () {
					return false;
				}
			}
		});
	}

	$scope.update = function(info){
		var modalInstance = $modal.open({
			template: require('../views/addTravel.html'),
			controller: 'addTravel',
			size: 'lg',
			resolve: {
				travel: function () {
					return info;
				}
			}
		});
		modalInstance.result.then(function(result) {
			$scope.getTravelList();
		});
	}

	$scope.setTravelStatus = function(info, status){
		var para = {
			'group_code': info.group_code,
			'status': status
		}
		$resource('/api/ac/goc/outboundTravelService/setTravelStatus', {}, {}).save(para, function(res){
            if (res.errcode === 0) {
				toaster.success({title: '', body: '成功'});
				info.status = status;
            } else {
                toaster.error({title: '', body: '失败'});
            }
        });
	}

	$scope.delete = function(group_code, index){
		if(confirm('确认删除此出境游信息吗?')){
			$resource('/api/ac/goc/outboundTravelService/deleteTravel', {}, {}).save({'group_code': group_code}, function(res){
				if (res.errcode === 0) {
					toaster.success({title: '', body: '成功'});
					$scope.list.splice(index, 1);
				} else {
					toaster.error({title: '', body: '失败'});
				}
			});
		}
	}

	$scope.onSale = function(info){
		var modalInstance = $modal.open({
			template: require('../views/outboundSale.html'),
			controller: 'outboundSale',
			size: 'lg',
			resolve: {
				travel: function () {
					return info;
				},
				getDate : function(utilservice){
					return utilservice.getDate;
				},
				flag : function(){
					return false;
				}
			}
		});
	}


};